package com.example.sunsg.okhttptest.bean;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by sunsg on 16/3/2.
 */
public class LocalImageItem implements Parcelable {
    /**标题*/
    public static final int TYPE_TITLE = 0;
    /**图片*/
    public static final int TYPE_IMAGE = 1;

    private int type;
    private LocalImageChildItem childItem;


    public LocalImageItem() {
    }

    public LocalImageItem(int type, LocalImageChildItem childItem) {
        this.type = type;
        this.childItem = childItem;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public LocalImageChildItem getChildItem() {
        return childItem;
    }

    public void setChildItem(LocalImageChildItem childItem) {
        this.childItem = childItem;
    }

    /**每个childitem 都要实现这个接口*/
    public interface  LocalImageChildItem {

    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.type);
        switch (type){
            case TYPE_TITLE:
                LocalImageItemTitle titleItem = (LocalImageItemTitle) childItem;
                dest.writeParcelable(titleItem, flags);
                break;
            case TYPE_IMAGE:
                LocalImageItemImage imageItem = (LocalImageItemImage) childItem;
                dest.writeParcelable(imageItem, flags);
                break;
        }

    }

    protected LocalImageItem(Parcel in) {
        this.type = in.readInt();
        this.childItem = in.readParcelable(LocalImageChildItem.class.getClassLoader());
//        switch (type){
//            case TYPE_TITLE:
//                this.childItem = in.readParcelable(LocalImageItemTitle.class.getClassLoader());
//                break;
//            case TYPE_IMAGE:
//                this.childItem = in.readParcelable(LocalImageItemImage.class.getClassLoader());
//                break;
//        }
    }

    public static final Parcelable.Creator<LocalImageItem> CREATOR = new Parcelable.Creator<LocalImageItem>() {
        public LocalImageItem createFromParcel(Parcel source) {
            return new LocalImageItem(source);
        }

        public LocalImageItem[] newArray(int size) {
            return new LocalImageItem[size];
        }
    };
}
